package cn.lcfms.app.admin.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.lcfms.app.admin.bean.MarkBean;
import cn.lcfms.bin.annotation.PermitPoll;
import cn.lcfms.bin.core.Application;
import cn.lcfms.bin.service.BaseService;
import cn.lcfms.bin.view.CommonEditLayer;
import cn.lcfms.bin.view.CommonPageView;


@PermitPoll(type="CMS管理",name="标签管理")
@Controller("admin.MarkController")
@RequestMapping("/admin/mark")
public class MarkController extends AdminBaseController{
	
	@RequestMapping("/list")
	public CommonPageView list() {
		BaseService service= Application.getService(MarkBean.class);
		service.column("mid as id","title as 标题");
		CommonPageView view=new CommonPageView("标记管理", service);
		view.setToolBarLayer("添加标记", "icon-jia", "edit", 400, 250);
		view.setDeleteLayer("delete?mid=${id}");
		return view;
	}
	
	@RequestMapping("/edit")
	public CommonEditLayer edit(@RequestParam(defaultValue="0",required=false)int mid) {
		CommonEditLayer view=new CommonEditLayer();
		if(mid>0) {
			BaseService service= Application.getService(MarkBean.class);
			MarkBean bean=service.selectOne(MarkBean.class, mid);
			view.setInputForm("标题", "title", bean.getTitle(), "unempty");
			view.setHiddenForm("mid", bean.getMid());
		}else {
			view.setInputForm("标题", "title", "", "unempty");
		}
		view.setFormAction("save");
		return view;
	}
	
	@RequestMapping("/save")
	public String edit(MarkBean bean) {
		BaseService service= Application.getService(MarkBean.class);
		if(bean.getMid()==0) {
			service.insert(bean);
		}else {
			service.update(bean);
		}
		return "{code:1,msg:保存成功！,url:list}";		
	}
	
	@RequestMapping("/delete")
	public String delete(int mid) {
		BaseService service= Application.getService(MarkBean.class);
		service.deleteById(mid);
		return "{code:1,msg:删除成功！,url:list}";		
	}
	
	
}
